from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, get_object_or_404
from tie8.models import *

root_of_boards = Stamp.objects.get(parent=None, label='.board')

def list_boards(request):
    result = []
    try:
        root = request.GET['board']
        root = get_object_or_404(Stamp, id=root)
    except KeyError:
        root = root_of_boards
        
    for i in root.children.all():
        result.append(str(i.id)+':rw:' + i.label)
    result = '\n'.join(result)
    return HttpResponse(result,  mimetype="text/plain")

def list_serials(request):
    result = []
    try:
        root = request.GET['board']
        root = get_object_or_404(Stamp, id=root)
    except KeyError:
        root = root_of_boards
        
    for i in root.children.all():
        result.append(str(i.id)+':rw:' + i.label)
    result = '\n'.join(result)
    return HttpResponse(result,  mimetype="text/plain")

